#include "led_control.h"

LedControl::LedControl(uint8_t pin) : _pin(pin), _state(false) {
}

void LedControl::begin() {
    pinMode(_pin, OUTPUT);
    turnOff(); // 初始状态为关闭
}

void LedControl::turnOn() {
    digitalWrite(_pin, HIGH);
    _state = true;
}

void LedControl::turnOff() {
    digitalWrite(_pin, LOW);
    _state = false;
}

void LedControl::toggle() {
    if (_state) {
        turnOff();
    } else {
        turnOn();
    }
}

bool LedControl::getState() {
    return _state;
}

void LedControl::blink(uint8_t times, unsigned long onTime, unsigned long offTime) {
    for (uint8_t i = 0; i < times; i++) {
        turnOn();
        delay(onTime);
        turnOff();
        if (i < times - 1) { // 在最后一次闪烁后不延迟
            delay(offTime);
        }
    }
} 